package cn.edu.niit.alienlab.jshttplessonserver.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class FileUploadConfig implements WebMvcConfigurer {
    //注入配置文件中配置的值
    @Value("${application.file.diskpath}")
    String diskPath;
    @Value("${application.file.fileurl}")
    String fileUrl;
    /**
     * 添加虚拟目录配置，将文件夹与访问路由绑定
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler(this.fileUrl+"/**") //访问的路由
                .addResourceLocations("file:" + this.diskPath); //对应的文件夹
    }
}
